package com.aigou.admin.aigouspringboot.service.impl;

import com.aigou.admin.aigouspringboot.common.Constants;
import com.aigou.admin.aigouspringboot.entity.Product;
import com.aigou.admin.aigouspringboot.entity.dto.ProductQueryDTO;
import com.aigou.admin.aigouspringboot.mapper.ProductMapper;
import com.aigou.admin.aigouspringboot.service.ProductService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author Mr.LiFuXing
 * @Date 2024/12/10 20:21
 * @Title ProductServiceImpl
 * @Package com.aigou.admin.aigouspringboot.service.impl
 */
@Service
public class ProductServiceImpl implements ProductService {

    @Resource
    private ProductMapper productMapper;

    @Override
    public List<Product> selectAll() {
        return productMapper.selectAll();
    }

    /**
     * 分页查询产品列表
     *
     * @param current 当前页
     * @return info 包含产品列表信息的分页对象
     */
    @Override
    public PageInfo<Product> selectProductListByPage(Integer current, ProductQueryDTO productQueryDTO) {
        // 分页插件，开启分页
        PageHelper.startPage(current, Constants.PAGE_SIZE);
        // 查询所有产品信息
        List<Product> productList = productMapper.selectSalesByCondition(productQueryDTO);
        // 把productList放入返回分页信息
        return new PageInfo<>(productList);
    }

    /**
     * 根据id删除产品
     *
     * @param id 产品的id
     * @return 受影响的行数，正常删除返回1
     */
    @Override
    public int deleteById(String id) {


        return productMapper.deleteByPrimaryKey(id);
    }

    /**
     * 根据id查询产品信息
     *
     * @param id 产品的id
     * @return 对应的产品对象
     */
    @Override
    public Product selectById(String id) {

        return productMapper.selectByPrimaryKey(id);
    }

    /**
     * 编辑产品信息
     *
     * @param product 要编辑的产品对象，包含修改后的数据
     * @return 受影响的行数，正常更新返回1
     */
    @Override
    public int edit(Product product) {

        return productMapper.updateByPrimaryKeySelective(product);
    }

    /**
     * 添加产品信息
     *
     * @param product 要添加的产品对象
     * @return 受影响的行数，正常插入返回1
     */
    @Override
    public int save(Product product) {

        return productMapper.insertSelective(product);
    }

    @Override
    public List<Product> selectAllByProductType() {
        return productMapper.selectAllByProductType();
    }

    @Override
    public List<Product> selectAllByProductTypeFuShi() {
        return productMapper.selectAllByProductTypeFuShi();
    }

    @Override
    public List<Product> selectAllByProductTypeMeiZhuang() {
        return productMapper.selectAllByProductTypeMeiZhuang();
    }

    @Override
    public List<Product> selectAllByProductTypeBook() {
        return productMapper.selectAllByProductTypeBook();
    }

    @Override
    public List<Product> selectProductByProductTypeID(String productTypeID) {
        return productMapper.selectProductByProductTypeID(productTypeID);
    }

    @Override
    public List<Product> selectByTime() {
        return productMapper.selectByTime();
    }


}